//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_getGear.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

private ["_player","_array_mag","_id","_display_name","_count","_array_class","_array_bullet","_array_class_x","_array_bullet_x","_r_mag_d","_h_mag_d","_brack","_items_count"
		,"_gear","_weapons","_prim_weap","_prim_items","_sec_weap","_sec_items","_items_assigned","_handgun","_handgun_items","_goggles","_headgear","_uniform","_uniform_items","_uniform_weap"
		,"_vest","_vest_items","_vest_weap","_back_pack","_back_pack_items","_back_pack_weap","_weap_sel","_weap_mode","_fire_mode_array","_fire_mode","_magazinesAmmoFull"
		,"_mag_uniform","_mag_vest","_mag_back","_mag_loaded_prim","_mag_loaded_sec","_mag_loaded_at","_ammo"];
_player = _this;
if (isnil "_player" || {(typename _player != typename objNull)} || {!(_player isKindOf "Man")}) then {
	TRACE_1("_player",_player);
	_player = player;
};

_items_count = 0;
_gear = [];
_weapons = [];
_prim_weap = primaryWeapon _player;
_prim_items = primaryWeaponItems _player;
_items_count = _items_count + (count _prim_items);
_sec_weap = secondaryWeapon _player;
_sec_items = secondaryWeaponItems _player;
_items_count = _items_count + (count _sec_items);
_items_assigned = assignedItems _player;
_items_count = _items_count + (count _items_assigned);
_handgun = handgunWeapon _player;
_handgun_items = handgunItems _player;
_items_count = _items_count + (count _handgun_items);
if (_prim_weap != "") then {_weapons = _weapons + [_prim_weap]};
if (_sec_weap != "") then {_weapons = _weapons + [_sec_weap]};
if (_handgun != "") then {_weapons = _weapons + [_handgun]};
_goggles = goggles _player;
_headgear = headgear _player;

_uniform = uniform _player;
_uniform_items = uniformItems _player;
_uniform_weap = getWeaponCargo (uniformContainer _player);
_items_count = _items_count + (count _uniform_items);

_vest = vest _player;
_vest_items = vestItems _player;
_vest_weap = getWeaponCargo (vestContainer _player);
_items_count = _items_count + (count _vest_items);

_back_pack = backpack _player;
_back_pack_items = backpackItems _player;
_back_pack_weap = getWeaponCargo (backpackContainer _player);
_items_count = _items_count + (count _back_pack_items);

_weap_sel = currentWeapon _player;
_weap_mode = currentWeaponMode _player;
_fire_mode_array = getArray (configFile >> "cfgWeapons" >> _weap_sel >> "modes");
_fire_mode = _fire_mode_array find _weap_mode;

_magazinesAmmoFull = magazinesAmmoFull _player;
_mag_uniform = [];_mag_vest = [];_mag_back = [];_mag_loaded_prim = [];_mag_loaded_sec = [];_mag_loaded_at = [];
{
	if !(_x select 2) then
	{
		switch (true) do
		{
			case ((_x select 4) == "Vest" && ((_x select 3) != 0) && (getNumber(configFile >> "cfgMagazines" >> (_x select 0) >> "count") > 1))     : {_mag_vest = _mag_vest + [[(_x select 0),(_x select 1)]]; _vest_items = _vest_items - [(_x select 0)];};
			case ((_x select 4) == "Uniform" && ((_x select 3) != 0) && (getNumber(configFile >> "cfgMagazines" >> (_x select 0) >> "count") > 1))  : {_mag_uniform = _mag_uniform + [[(_x select 0),(_x select 1)]]; _uniform_items = _uniform_items - [(_x select 0)];};
			case ((_x select 4) == "Backpack" && ((_x select 3) != 0) && (getNumber(configFile >> "cfgMagazines" >> (_x select 0) >> "count") > 1)) : {_mag_back = _mag_back + [[(_x select 0),(_x select 1)]]; _back_pack_items = _back_pack_items - [(_x select 0)];};
		};
	}
	else
	{
		switch (true) do
		{
			case ((_x select 3) == 1)  : {_mag_loaded_prim set [count _mag_loaded_prim, [(_x select 0),(_x select 1)]]};
			case ((_x select 3) == 2)  : {_mag_loaded_sec = [(_x select 0),(_x select 1)]};
			case ((_x select 3) == 4) : {_mag_loaded_at = [(_x select 0),(_x select 1)]};
		};
	};
	INC(_items_count);
} foreach _magazinesAmmoFull;
_ammo = [_mag_loaded_prim,_mag_loaded_sec,_mag_loaded_at,_mag_uniform,_mag_vest,_mag_back];
_gear =
[
	_uniform,
	_vest,
	_goggles,
	_headgear,
	_back_pack,
	_back_pack_items,
	_back_pack_weap,
	_weapons,
	_prim_items,
	_sec_items,
	_handgun_items,
	_items_assigned,
	_uniform_items,
	_uniform_weap,
	_vest_items,
	_vest_weap,
	_weap_sel,
	_fire_mode,
	_ammo
];
TRACE_1("Items Count",_items_count);
#ifdef __FORCE_TRACE__
{ TRACE_1("",_x);
} foreach _gear;
#endif
_gear
